<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //实现一元数组遍历
        function traverse(arr, callback) {
            for (let i = 0; i < arr.length; i++) {
                callback(arr[i], i, arr);
            }
        }
        // 示例使用
        const myArray = [1, 2, 3, 4, 5];
        traverse(myArray, (element, index, array) => {
            console.log(`Element: ${element}, Index: ${index}`);
        }   );
    </script>
</body>
</html>